package com.vogtec.fota.dao;

import com.vogtec.fota.dao.model.Bike;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wei on 2017/7/15.
 */
public interface BikeDao {

    String TABLE = "bike";

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert(" insert into " + TABLE + " set " +
                    "bikeNum=#{bikeNum}," +
                    "status=#{status}," +
                    "upgrade_task=#{upgradeTask}"
    )
    int insert(Bike bike);

    @Select(" select * from " + TABLE + " where upgrade_task=#{upgrade_task}")
    ArrayList<Bike> selectBikes (@Param("upgrade_task") int upgrade_task);

    @Select(" select count(*) from " + TABLE + " where upgrade_task=#{upgrade_task}")
    int selectBikeCount (@Param("upgrade_task") int upgrade_task);

    @Select(" select count(*) from " + TABLE + " where upgrade_task=#{upgrade_task} and status=#{status}")
    int selectStatusCount (@Param("upgrade_task") int upgrade_task,@Param("status") int status);

    @Update(" update " + TABLE + " set status=#{status} where bikeNum=#{bikeNum}")
    void updateStatus (@Param("status") int status,@Param("bikeNum") String bikeNum);

    @Update(" update " + TABLE + " set status=#{status} where upgrade_task=#{upgrade_task}")
    void updateStatusByUpgrade_task (@Param("status") int status,@Param("upgrade_task") int upgrade_task);

    @Select(" select * from " + TABLE + " where bikeNum=#{bikeNum} and upgrade_task=#{upgrade_task}")
    Bike selectBikeByIdBikeNum (@Param("bikeNum") String bikeNum,@Param("upgrade_task") int upgrade_task);

    @Delete(" delete from " + TABLE + " where upgrade_task=#{id}")
    int delete(@Param("id") Integer id);

    @Select(" select bikeNum from " + TABLE + " where upgrade_task=#{id}")
    List<String> selectBikeNumById(@Param("id") Integer id);

}